package com.j256.ormlite.android.apptools;

import android.content.Context;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import com.j256.ormlite.android.AndroidConnectionSource;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.logger.Logger;
import com.j256.ormlite.logger.LoggerFactory;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.DatabaseTableConfigLoader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.SQLException;

public abstract class OrmLiteSqliteOpenHelper extends SQLiteOpenHelper
{
  protected static Logger logger = LoggerFactory.getLogger(OrmLiteSqliteOpenHelper.class);
  protected boolean cancelQueriesEnabled;
  protected AndroidConnectionSource connectionSource = new AndroidConnectionSource(this);
  private volatile boolean isOpen = true;

  public OrmLiteSqliteOpenHelper(Context paramContext, String paramString, SQLiteDatabase.CursorFactory paramCursorFactory, int paramInt)
  {
    super(paramContext, paramString, paramCursorFactory, paramInt);
    logger.trace("{}: constructed connectionSource {}", this, this.connectionSource);
  }

  public OrmLiteSqliteOpenHelper(Context paramContext, String paramString, SQLiteDatabase.CursorFactory paramCursorFactory, int paramInt1, int paramInt2)
  {
    this(paramContext, paramString, paramCursorFactory, paramInt1, openFileId(paramContext, paramInt2));
  }

  public OrmLiteSqliteOpenHelper(Context paramContext, String paramString, SQLiteDatabase.CursorFactory paramCursorFactory, int paramInt, File paramFile)
  {
    this(paramContext, paramString, paramCursorFactory, paramInt, openFile(paramFile));
  }

  public OrmLiteSqliteOpenHelper(Context paramContext, String paramString, SQLiteDatabase.CursorFactory paramCursorFactory, int paramInt, InputStream paramInputStream)
  {
    super(paramContext, paramString, paramCursorFactory, paramInt);
    if (paramInputStream == null)
      return;
    try
    {
      DaoManager.addCachedDatabaseConfigs(DatabaseTableConfigLoader.loadDatabaseConfigFromReader(new BufferedReader(new InputStreamReader(paramInputStream), 4096)));
      try
      {
        paramInputStream.close();
        return;
      }
      catch (IOException localIOException2)
      {
        return;
      }
    }
    catch (SQLException localSQLException)
    {
      localSQLException = localSQLException;
      throw new IllegalStateException("Could not load object config file", localSQLException);
    }
    finally
    {
    }
    try
    {
      paramInputStream.close();
      label87: throw localObject;
    }
    catch (IOException localIOException1)
    {
      break label87;
    }
  }

  private static InputStream openFile(File paramFile)
  {
    if (paramFile == null)
      return null;
    try
    {
      FileInputStream localFileInputStream = new FileInputStream(paramFile);
      return localFileInputStream;
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      throw new IllegalArgumentException("Could not open config file " + paramFile, localFileNotFoundException);
    }
  }

  private static InputStream openFileId(Context paramContext, int paramInt)
  {
    InputStream localInputStream = paramContext.getResources().openRawResource(paramInt);
    if (localInputStream == null)
      throw new IllegalStateException("Could not find object config file with id " + paramInt);
    return localInputStream;
  }

  public void close()
  {
    super.close();
    this.connectionSource.close();
    this.isOpen = false;
  }

  public ConnectionSource getConnectionSource()
  {
    if (!this.isOpen)
      logger.warn(new IllegalStateException(), "Getting connectionSource was called after closed");
    return this.connectionSource;
  }

  public <D extends Dao<T, ?>, T> D getDao(Class<T> paramClass)
    throws SQLException
  {
    return DaoManager.createDao(getConnectionSource(), paramClass);
  }

  public <D extends RuntimeExceptionDao<T, ?>, T> D getRuntimeExceptionDao(Class<T> paramClass)
  {
    try
    {
      RuntimeExceptionDao localRuntimeExceptionDao = new RuntimeExceptionDao(getDao(paramClass));
      return localRuntimeExceptionDao;
    }
    catch (SQLException localSQLException)
    {
      throw new RuntimeException("Could not create RuntimeExcepitionDao for class " + paramClass, localSQLException);
    }
  }

  public boolean isOpen()
  {
    return this.isOpen;
  }

  // ERROR //
  public final void onCreate(SQLiteDatabase paramSQLiteDatabase)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 155	com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper:getConnectionSource	()Lcom/j256/ormlite/support/ConnectionSource;
    //   4: astore_2
    //   5: aload_2
    //   6: invokeinterface 182 1 0
    //   11: astore_3
    //   12: iconst_0
    //   13: istore 4
    //   15: aload_3
    //   16: ifnonnull +28 -> 44
    //   19: new 184	com/j256/ormlite/android/AndroidDatabaseConnection
    //   22: dup
    //   23: aload_1
    //   24: iconst_1
    //   25: aload_0
    //   26: getfield 186	com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper:cancelQueriesEnabled	Z
    //   29: invokespecial 189	com/j256/ormlite/android/AndroidDatabaseConnection:<init>	(Landroid/database/sqlite/SQLiteDatabase;ZZ)V
    //   32: astore_3
    //   33: aload_2
    //   34: aload_3
    //   35: invokeinterface 193 2 0
    //   40: pop
    //   41: iconst_1
    //   42: istore 4
    //   44: aload_0
    //   45: aload_1
    //   46: aload_2
    //   47: invokevirtual 196	com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper:onCreate	(Landroid/database/sqlite/SQLiteDatabase;Lcom/j256/ormlite/support/ConnectionSource;)V
    //   50: iload 4
    //   52: ifeq +10 -> 62
    //   55: aload_2
    //   56: aload_3
    //   57: invokeinterface 200 2 0
    //   62: return
    //   63: astore 5
    //   65: new 88	java/lang/IllegalStateException
    //   68: dup
    //   69: ldc 202
    //   71: aload 5
    //   73: invokespecial 93	java/lang/IllegalStateException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   76: athrow
    //   77: astore 7
    //   79: iload 4
    //   81: ifeq +10 -> 91
    //   84: aload_2
    //   85: aload_3
    //   86: invokeinterface 200 2 0
    //   91: aload 7
    //   93: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   33	41	63	java/sql/SQLException
    //   44	50	77	finally
  }

  public abstract void onCreate(SQLiteDatabase paramSQLiteDatabase, ConnectionSource paramConnectionSource);

  // ERROR //
  public final void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 155	com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper:getConnectionSource	()Lcom/j256/ormlite/support/ConnectionSource;
    //   4: astore 4
    //   6: aload 4
    //   8: invokeinterface 182 1 0
    //   13: astore 5
    //   15: iconst_0
    //   16: istore 6
    //   18: aload 5
    //   20: ifnonnull +31 -> 51
    //   23: new 184	com/j256/ormlite/android/AndroidDatabaseConnection
    //   26: dup
    //   27: aload_1
    //   28: iconst_1
    //   29: aload_0
    //   30: getfield 186	com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper:cancelQueriesEnabled	Z
    //   33: invokespecial 189	com/j256/ormlite/android/AndroidDatabaseConnection:<init>	(Landroid/database/sqlite/SQLiteDatabase;ZZ)V
    //   36: astore 5
    //   38: aload 4
    //   40: aload 5
    //   42: invokeinterface 193 2 0
    //   47: pop
    //   48: iconst_1
    //   49: istore 6
    //   51: aload_0
    //   52: aload_1
    //   53: aload 4
    //   55: iload_2
    //   56: iload_3
    //   57: invokevirtual 207	com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper:onUpgrade	(Landroid/database/sqlite/SQLiteDatabase;Lcom/j256/ormlite/support/ConnectionSource;II)V
    //   60: iload 6
    //   62: ifeq +12 -> 74
    //   65: aload 4
    //   67: aload 5
    //   69: invokeinterface 200 2 0
    //   74: return
    //   75: astore 7
    //   77: new 88	java/lang/IllegalStateException
    //   80: dup
    //   81: ldc 202
    //   83: aload 7
    //   85: invokespecial 93	java/lang/IllegalStateException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   88: athrow
    //   89: astore 9
    //   91: iload 6
    //   93: ifeq +12 -> 105
    //   96: aload 4
    //   98: aload 5
    //   100: invokeinterface 200 2 0
    //   105: aload 9
    //   107: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   38	48	75	java/sql/SQLException
    //   51	60	89	finally
  }

  public abstract void onUpgrade(SQLiteDatabase paramSQLiteDatabase, ConnectionSource paramConnectionSource, int paramInt1, int paramInt2);

  public String toString()
  {
    return getClass().getSimpleName() + "@" + Integer.toHexString(super.hashCode());
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
 * JD-Core Version:    0.6.2
 */